eric7.DebugClients.Python.FlexModuleCompleter

Module word completion for the eric-ide shell.

NOTE for eric-ide variant

This version is a re-implementation of _module_completer as found in the Python3 library. It is modified to work with the eric-ide debug client.

Global Attributes

None

Classes

ImportParser Class to Parse incomplete import statements that are suitable for autocomplete suggestions.
ModuleCompleter Class implementing a completer for Python import statements.
ParseError Class representing a parsing issue.
Result Class implementing the result data structure.
TokenQueue Class implementing helper functions for working with a sequence of tokens.

Functions

None


ImportParser

Class to Parse incomplete import statements that are suitable for autocomplete suggestions.

Examples: - import foo -> Result(from_name=None, name='foo') - import foo. -> Result(from_name=None, name='foo.') - from foo -> Result(from_name='foo', name=None) - from foo import bar -> Result(from_name='foo', name='bar') - from .foo import ( -> Result(from_name='.foo', name='')

Note that the parser works in reverse order, starting from the last token in the input string. This makes the parser more robust when parsing multiple statements.

Derived from

None

Class Attributes

_ignored_tokens
_keywords

Class Methods

None

Methods

ImportParser Constructor
_parse Protected method parse the supported import variants.
parse Public method to parse the code line.
parse_as_name Public method to parse the as part.
parse_as_names Public method to parse the as parts.
parse_dotted_as_name Public method to parse a dotted as name.
parse_dotted_name Public method to parse a dotted name.
parse_empty_from_import Public method to parse an empty from...import statement.
parse_from Public method to parse the from part.
parse_from_import Public method to parse a from...import statement.
parse_import Public method to parse a simple import statement.

Static Methods

None

ImportParser (Constructor)

ImportParser(code_line)

Constructor

code_line (str)
line of code to be parsed

ImportParser._parse

_parse()

Protected method parse the supported import variants.

Return:
result of the parse operation
Return Type:
Result

ImportParser.parse

parse()

Public method to parse the code line.

Return:
tuple containing the package name and the module name
Return Type:
tuple of (str, str)

ImportParser.parse_as_name

parse_as_name()

Public method to parse the as part.

ImportParser.parse_as_names

parse_as_names()

Public method to parse the as parts.

ImportParser.parse_dotted_as_name

parse_dotted_as_name()

Public method to parse a dotted as name.

Return:
module name
Return Type:
str

ImportParser.parse_dotted_name

parse_dotted_name()

Public method to parse a dotted name.

Return:
dotted module name
Return Type:
str
Raises ParseError:
DESCRIPTION

ImportParser.parse_empty_from_import

parse_empty_from_import()

Public method to parse an empty from...import statement.

Return:
package name
Return Type:
str

ImportParser.parse_from

parse_from()

Public method to parse the from part.

Return:
package name
Return Type:
str

ImportParser.parse_from_import

parse_from_import()

Public method to parse a from...import statement.

Return:
result of the parse operation
Return Type:
Result
Raises ParseError:
DESCRIPTION

ImportParser.parse_import

parse_import()

Public method to parse a simple import statement.

Return:
result of the parse operation
Return Type:
Result
Raises ParseError:
DESCRIPTION
Up


ModuleCompleter

Class implementing a completer for Python import statements.

Examples: - import - import foo - import foo. - import foo as bar, baz

- from - from foo - from foo import - from foo import bar - from foo import (bar as baz, qux

Derived from

None

Class Attributes

None

Class Methods

None

Methods

ModuleCompleter Constructor
_find_modules Protected method to find all modules under 'path' that start with 'prefix' (even invalid module names).
complete Public method to complete module or submodule names.
find_modules Public method to find all modules under 'path' that start with 'prefix'.
format_completion Public method to format a valid module path.
get_completions Public method to get the next possible import completions for 'line'.
get_path_and_prefix Public method to split a dotted name into an import path and a final prefix that is to be completed.
global_cache Public method implementing the global module cache.
is_suggestion_match Public method to ckeck, if 'module_name' is a valid suggestion.
iter_submodules Public method to iterate over all submodules of the given parent modules.
resolve_relative_name Public method to resolve a relative module name to an absolute name.

Static Methods

None

ModuleCompleter (Constructor)

ModuleCompleter(namespace=None)

Constructor

namespace (dict or FrameLocalsProxy (optional))
namespace for the completer (defaults to None)

ModuleCompleter._find_modules

_find_modules(path, prefix)

Protected method to find all modules under 'path' that start with 'prefix' (even invalid module names).

path (str)
path to find modules in
prefix (str)
module prefix to look for
Return:
list of modules
Return Type:
list of str

ModuleCompleter.complete

complete(from_name, name)

Public method to complete module or submodule names.

from_name (str)
name of modules to import from
name (str)
name part to be completed
Return:
list of completions
Return Type:
list of str

ModuleCompleter.find_modules

find_modules(path, prefix)

Public method to find all modules under 'path' that start with 'prefix'.

path (str)
path to find modules in
prefix (str)
module prefix to look for
Return:
list of modules
Return Type:
list of str

ModuleCompleter.format_completion

format_completion(path, module)

Public method to format a valid module path.

path (str)
path component
module (str)
module name
Return:
formatted module name
Return Type:
str

ModuleCompleter.get_completions

get_completions(line)

Public method to get the next possible import completions for 'line'.

line (str)
line of code to get completions for
Return:
list of potential completions
Return Type:
list of str

ModuleCompleter.get_path_and_prefix

get_path_and_prefix(dotted_name)

Public method to split a dotted name into an import path and a final prefix that is to be completed.

Examples: 'foo.bar' -> 'foo', 'bar' 'foo.' -> 'foo', '' '.foo' -> '.', 'foo'

dotted_name (str)
dotted modules name to be split
Return:
tuple containing the import path and the final prefix
Return Type:
tuple of (str, str)

ModuleCompleter.global_cache

global_cache()

Public method implementing the global module cache.

Return:
reference to the global cache object
Return Type:
list of pkgutil.ModuleInfo

ModuleCompleter.is_suggestion_match

is_suggestion_match(module_name, prefix)

Public method to ckeck, if 'module_name' is a valid suggestion.

module_name (str)
module name to be checked
prefix (str)
module name prefix to check against
Return:
flag indicating a valid suggestion
Return Type:
bool

ModuleCompleter.iter_submodules

iter_submodules(parent_modules)

Public method to iterate over all submodules of the given parent modules.

parent_modules (list of pkgutil.ModuleInfo)
list of module info objects to be processed
Return:
iterator of all submodules
Return Type:
iterator of pkgutil.ModuleInfo

ModuleCompleter.resolve_relative_name

resolve_relative_name(name, package)

Public method to resolve a relative module name to an absolute name.

Example: resolve_relative_name('.foo', 'bar') -> 'bar.foo'

name (str)
relative module name
package (str)
package name
Return:
absolute module name
Return Type:
str or None
Up


ParseError

Class representing a parsing issue.

Derived from

Exception

Class Attributes

None

Class Methods

None

Methods

None

Static Methods

None
Up


Result

Class implementing the result data structure.

Derived from

None

Class Attributes

from_name
name

Class Methods

None

Methods

None

Static Methods

None
Up


TokenQueue

Class implementing helper functions for working with a sequence of tokens.

Derived from

None

Class Attributes

None

Class Methods

None

Methods

TokenQueue Constructor
__bool__ Special method implementing the 'bool' logic.
peek Public method to get the next token without popping it.
peek_name Public method to check, if the next token is a name token without popping it.
peek_string Public method check, if the next token has a specific value.
pop Public method to pop the next token off the stack.
pop_name Public method to pop a name token off the token stack.
pop_string Public method to pop the next token and return its value, if it is of a specific name.
save_state Public method implementing a context manager to save the current state.

Static Methods

None

TokenQueue (Constructor)

TokenQueue(tokens)

Constructor

tokens (list of TokenInfo)
list of token info objects

TokenQueue.__bool__

__bool__()

Special method implementing the 'bool' logic.

Return:
flag indicating the boolean state
Return Type:
bool

TokenQueue.peek

peek()

Public method to get the next token without popping it.

Return:
next token
Return Type:
TokenInfo

TokenQueue.peek_name

peek_name()

Public method to check, if the next token is a name token without popping it.

Return:
flag indicating that the next token is a name token
Return Type:
TokenInfo

TokenQueue.peek_string

peek_string(token_string)

Public method check, if the next token has a specific value.

token_string (str)
string to test against
Return:
flag indicating that the next token has the specified value
Return Type:
bool

TokenQueue.pop

pop()

Public method to pop the next token off the stack.

Return:
next token
Return Type:
TokenInfo
Raises ParseError:
raised to indicate an empty token queue.

TokenQueue.pop_name

pop_name()

Public method to pop a name token off the token stack.

Return:
value of the name token
Return Type:
str
Raises ParseError:
raised to indicate that the popped token is not a name token

TokenQueue.pop_string

pop_string(token_string)

Public method to pop the next token and return its value, if it is of a specific name.

token_string (str)
string to test against
Return:
token value
Return Type:
str
Raises ParseError:
raised to indicate an invalid or unexpected token

TokenQueue.save_state

save_state()

Public method implementing a context manager to save the current state.

Up